package com.wy.service.impl.wy;

import com.wy.bean.HouseBean;
import com.wy.constants.CommonConstants;
import com.wy.constants.CommonValues;
import com.wy.dao.HousesMapper;
import com.wy.model.sys.Houses;
import com.wy.service.wy.HouseService;
import com.wy.utils.FileUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

@Service("houseServiceImpl")
public class HouseServiceImpl implements HouseService {

	@Autowired
	private HousesMapper houseDao;
	@Autowired
	private CommonValues commonValues;

	@Override
	public List<HouseBean> houseList(Integer pageSize, Integer start, Integer buildingId, String houseCode,List<String> rids,Integer residenceId) {
		return houseDao.houseList(pageSize,start,buildingId,houseCode,rids,residenceId);
	}

	@Override
	public Integer houseSize(Integer pageSize, Integer start,Integer buildingId,String houseCode,List<String> rids,Integer residenceId) {
		return houseDao.houseSize(pageSize,start,buildingId,houseCode,rids,residenceId);
	}

	@Override
	public List<Houses> getHousesByBuildingId(Integer buildingID) {
		return houseDao.getHousesByBuildingId(buildingID);
	}

	@Override
	public void insertHouse(HouseBean houses) {
		houses.setExt3(FileUtil.moveFilePath(commonValues.getBasePath() + houses.getExt3(),
				String.format(commonValues.getLocalPath(),houses.getProjectName(),CommonConstants.HOUSE),
				houses.getHouseName()+".jpg"));
		houseDao.insert(houses);
	}

	@Override
	public void updateHouse(HouseBean houses) {
		houses.setExt3(FileUtil.moveFilePath(commonValues.getBasePath() + houses.getExt3(),
				String.format(commonValues.getLocalPath(),houses.getProjectName(),CommonConstants.HOUSE),
				houses.getHouseName()+".jpg"));
		houseDao.updateByPrimaryKey(houses);
	}

	@Override
	public void deleteHouses(Integer hid) {
		houseDao.deleteByPrimaryKey(hid);
	}

	@Override
	public void deleteHouses(List<String> hid) {
		houseDao.deleteHouses(hid);
	}

	@Override
	public List<Houses> getHouseList() {
		return houseDao.getHouseList();
	}

	@Override
	public List<HouseBean> getHouseListImport(List<HouseBean> list) {
		return houseDao.getHouseListImport(list);
	}

	@Override
	public void insertBatch(List<HouseBean> list) {
		houseDao.insertBatch(list);
	}

	@Override
	public List<String> getUnitByBuildingId(Integer buildingId) {
		return houseDao.getUnitByBuildingId(buildingId);
	}

	@Override
	public List<Houses> getHousesByBidUnit(Integer buildingId,String unitName) {
		return houseDao.getHousesByBidUnit(buildingId,unitName);
	}
}
